// 立即执行函数可以创建闭包
let Singleton = (function() {
    let instance; //undefined
    return function(name) {
        // 返回实例
        if (instance) {
            return instance
        }
        this.name = name;
        return instance = this;
    }
})();

Singleton.prototype.getName = function() {
    console.log(this.name);
}

let Winner = new Singleton('winner');
let Looser = new Singleton('Looser')
console.log(Winner == Looser);
Winner.getName();